﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SBLL;
using SMODEL;

namespace 考试平台.Controllers
{
    public class LoginInController : Controller
    {
        //
        // GET: /LoginIn/
        Users_bll bll = new Users_bll();

        /// <summary>
        /// 登录界面显示
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            Session["user"] = null;
            return View();
        }

        /// <summary>
        /// 登录传值判断
        /// </summary>
        /// <returns></returns>
        public ActionResult LoginDo()
        {
            string name = Request["username"];
            string pwd = Request["password"];
            List<Users_model> list = bll.GetList();
            Users_model user = list.Where(p => p.UserName == name && p.UserPwd == pwd).FirstOrDefault();
            if (user != null)
            {
                Session["user"] = user;
                return Content("<script>alert('登录成功！');location.href='/Home/Index'</script>");
            }
            else
            {
                return Content("<script>alert('用户名或密码有误！');location.href='/LoginIn/Index'</script>");
            }
        }

    }
}
